package com.zm.core.controller;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.LogFactory;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.jfinal.plugin.activerecord.Record;
import com.taobao.api.FileItem;
import com.zm.core.common.controller.BaseController;
import com.zm.core.model.Comment;
import com.zm.core.model.Product;
import com.zm.core.model.Templet;
import com.zm.core.model.User;
import com.zm.core.model.Usize;
import com.zm.core.util.Log;
import com.zm.core.util.ZmUtil;
import com.zm.taobao.API;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class SellerAdminController extends BaseController {

	final String[] commentTag = new String[] { "鞋子软硬", "裤子搭配", "实物颜色", "透气性能" };

	public void index() {
		User user = getSessionAttr("currentuser");
		if (null == user) {
			setSessionAttr("currentuser", API.getCurrentUser());
			user = getSessionAttr("currentuser");
		}
		List<Record> xlist = Db.find("select DATE_FORMAT(use_time, '%Y-%m-%d' )as time from u_use_log where seller='" + user.getUser_id()
				+ "' and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(use_time) group by DATE_FORMAT(use_time, '%Y-%m-%d')");
		String x[] = new String[xlist.size()];
		for (int i = 0; i < xlist.size(); i++) {
			x[i] = xlist.get(i).get("time").toString();
		}

		List<Record> lablist = Db.find("select type from u_use_care group by type");
		String lab[] = new String[lablist.size()];
		for (int i = 0; i < lablist.size(); i++) {
			lab[i] = lablist.get(i).get("type").toString();
		}

		List<Record> y = new ArrayList<Record>();
		for (Record r : lablist) {
			String ysql = "select 'line' as type,type as name,count(type) as sum from u_use_log left join (SELECT * from u_use_care where type='"
					+ r.get("type").toString() + "') u_use_care on u_use_log.id=u_use_care.uselog_id where seller='" + user.getUser_id()
					+ "' and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(u_use_log.use_time) GROUP BY DATE_FORMAT( u_use_log.use_time, '%Y-%m-%d') ,u_use_care.type;";
			List<Record> ylist = Db.find(ysql);
			int yarray[] = new int[ylist.size()];
			for (int i = 0; i < ylist.size(); i++) {
				yarray[i] = Integer.parseInt(ylist.get(i).get("sum").toString());
			}
			r.set("data", JSONArray.fromObject(yarray).toString());
			// r.remove("sum");
			y.add(r);
		}
		List<Record> lablist2 = Db.find("select id from u_use_log where seller='" + user.getUser_id() + "'");
		if (lablist2 != null) {
			setAttr("usecount", lablist2.size());
		} else {
			setAttr("usecount", "0");
		}
		setAttr("x", JSONArray.fromObject(x).toString());
		setAttr("lab", JSONArray.fromObject(lab).toString());
		setAttr("y", JSONArray.fromObject(y).toString());
		render("seller/index.html");
	}

	public void toProductList() {
		User user = getSessionAttr("currentuser");
		if (null == user) {
			setSessionAttr("currentuser", API.getCurrentUser());
			user = getSessionAttr("currentuser");
		}
		List<Product> onSale = null;
		List<Product> products = new ArrayList<Product>();
		List<Product> queryproducts = new ArrayList<Product>();

		String searchkey = "";

		try {
			searchkey = getPara("searchkey");
			// searchkey = new
			// String(getPara("searchkey").getBytes("iso-8859-1"), "utf-8");
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		try {
			if (searchkey != null && !searchkey.equals("")) {
				List<Product> prod = getSessionAttr("products");
				if (prod == null) {
					onSale = API.getOnSaleProduct(searchkey);
				} else {
					List<Product> a = new ArrayList<Product>();
					for (int i = 0; i < prod.size(); i++) {
						if (prod.get(i).getTitle().indexOf(searchkey) != -1) {
							a.add(prod.get(i));
						}
					}
					onSale = a;
				}
			} else {
				List<Product> prod = getSessionAttr("products");
				if (prod == null) {
					onSale = API.getOnSaleProduct("");
					setSessionAttr("products", onSale);
				} else {
					onSale = prod;
				}
			}
			if (onSale != null) {
				products.addAll(onSale);
			}
			// 修改发布状态
			if (getPara("state") != null) {
				Product pro = Product.dao.findFirst("select * from u_product where product_id=" + getPara("numid"));
				if (pro != null) {
					pro.set("publish", getPara("state"));
					pro.update();
					String desc = API.getProductDetail(getPara("numid"));
					if (desc != null) {
						String aa = delImg(desc);
						API.updateProductDesc(getPara("numid"), aa);
					}
				}
			}
			for (int i = 0; i < products.size(); i++) {
				Product product = Product.dao.findFirst("select * from u_product where product_id='" + products.get(i).getNum_iid() + "'");
				if (product == null) {
					products.get(i).setSize_status("未添加");
					products.get(i).setPublish("未发布");
				} else {
					products.get(i).setSize_status("已添加");
					if ("0".equals(product.getStr("publish"))) {
						products.get(i).setPublish("未发布");
					} else {
						products.get(i).setPublish("已发布");
					}
					List<Record> alllist = Db
							.find("select id from u_use_log where seller='" + user.getUser_id() + "' and product_id=" + product.getStr("product_id"));
					if (alllist != null) {
						products.get(i).setUseCount(alllist.size());
					}
				}
				if (getPara("havesize") == null || getPara("havesize").equals("")) {
					queryproducts.add(products.get(i));
				} else if (getPara("havesize").equals("true") && products.get(i).getSize_status().equals("已添加")) {
					queryproducts.add(products.get(i));
				} else if (getPara("havesize").equals("false") && products.get(i).getSize_status().equals("未添加")) {
					queryproducts.add(products.get(i));
				}
			}

			String pageNo = getPara("pageNo");
			if (pageNo == null || pageNo.equals("")) {
				pageNo = 1 + "";
			}
			setAttr("products", getProductPage(Integer.parseInt(pageNo), 10, queryproducts));
			setAttr("pageNo", Integer.parseInt(pageNo));
			setAttr("pageCount", queryproducts.size() % 10 == 0 ? queryproducts.size() / 10 : queryproducts.size() / 10 + 1);
			setAttr("num", queryproducts.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
		render("seller/productList.html");
	}

	/**
	 * 通过页码编号获取出当前页的商品
	 * 
	 * @param pageNo
	 * @param p
	 * @return
	 */
	public static List<Product> getProductPage(int pageNo, int pageSize, List<Product> p) {
		List<Product> pro = new ArrayList<Product>();
		int count = pageSize * pageNo;
		for (int i = 0; i < p.size(); i++) {
			if (p.size() >= count) {
				if (i >= ((pageNo - 1) * pageSize) && i <= (count - 1)) {
					pro.add(p.get(i));
				}
			} else {
				if ((i >= ((pageNo - 1) * pageSize)) && (i <= p.size())) {
					pro.add(p.get(i));
				}
			}
		}
		return pro;
	}

	public void toProductDetail() {
		String numid = getPara("numid");
		User user = getSessionAttr("currentuser");
		List<String> titList = new ArrayList<String>();
		String title = null;
		try {
			// title = new String(getPara("title").getBytes("iso-8859-1"),
			// "utf-8");
			title = getPara("title");
			System.out.println(title);
			if (numid != null && !numid.equals("") && user != null) {
				List<Comment> evaList = getEvaluateByNumId(numid);
				List<Templet> list = Templet.dao.find("select title from u_templet where seller_id=" + user.getUser_id() + " group by title");
				if (list != null && list.size() > 0) {
					titList = new ArrayList<String>();
					for (Templet templet : list) {
						titList.add(templet.getStr("title"));
					}
				}
				Product product = Product.dao.findFirst("select * from u_product where product_id=" + numid);
				List<Comment> comment = Comment.dao.find("select * from u_comment where product_id=" + numid);
				List<Usize> sizeList = Usize.dao.find("select * from u_size where product_id='" + numid + "'");
				if (sizeList != null && sizeList.size() > 0) {
					setAttr("sizeList", sizeList);
					setAttr("isman", sizeList.get(0).get("sex"));
					String type = sizeList.get(0).getStr("style");
					setAttr("type", type.indexOf("非运动") == -1 ? "1" : "0");
				}

				if (comment != null && comment.size() > 0) {
					List<String> comment1 = new ArrayList<String>();
					List<String> comment2 = new ArrayList<String>();
					List<String> comment3 = new ArrayList<String>();
					List<String> comment4 = new ArrayList<String>();
					for (int i = 0; i < comment.size(); i++) {
						if (comment.get(i).getStr("type").equals(commentTag[0])) {

							comment1.add(comment.get(i).getStr("content"));
						} else if (comment.get(i).getStr("type").equals(commentTag[1])) {

							comment2.add(comment.get(i).getStr("content"));
						} else if (comment.get(i).getStr("type").equals(commentTag[2])) {

							comment3.add(comment.get(i).getStr("content"));
						} else if (comment.get(i).getStr("type").equals(commentTag[3])) {

							comment4.add(comment.get(i).getStr("content"));
						}
					}
					setAttr("comment1", comment1);
					setAttr("comment2", comment2);
					setAttr("comment3", comment3);
					setAttr("comment4", comment4);
				}
				titList.add(0, "------请选择模板------");
				setAttr("pro", product);
				setAttr("titList", titList);
				setAttr("numid", numid);
				setAttr("title", title);
				setAttr("evaList", evaList);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		render("seller/productDetail.html");
	}

	/**
	 * 卖家插入自家商品的信息
	 * 
	 * @author 李彤彤
	 * @date 2015年10月20日 下午2:03:33
	 */
	public void insertProduct() {
		try {
			final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			final String comment1 = getPara("comment1");
			final String comment2 = getPara("comment2");
			final String comment3 = getPara("comment3");
			final String comment4 = getPara("comment4");

			final String numid = getPara("numid");
			final String title = getPara("title");
			final String gsizes = getPara("gsizes");
			final String bsizes = getPara("bsizes");
			final String isman = getPara("isman");
			final String sizes = getPara("sizes");
			final String stout = getPara("stout");
			final String normal = getPara("normal");
			final String lean = getPara("lean");
			String sport = getPara("sport");
			final String[] sizearr = sizes.split(",");
			boolean succeed = false;
			if (sport.equals("皮鞋")) {
				sport = "非运动";
			} else {
				sport = "运动";
			}
			final String styl = sport;
			User user = getSessionAttr("currentuser");
			if (user == null) {
				renderText("添加失败，授权超时");
				return;
			}
			final Product product = Product.dao.findFirst("select * from u_product where product_id=?", numid);

			if (product != null) {
				Db.update("delete  from u_product where product_id=" + numid);
				Db.update("delete  from u_size where product_id=" + numid);
				Db.update("delete  from u_comment where product_id=" + numid);
			}

			succeed = Db.tx(new IAtom() {
				public boolean run() throws SQLException {
					boolean suc = true;
					final Record pro = new Record();
					pro.set("product_id", numid);
					pro.set("product_name", title);
					pro.set("create_time", new Date());
					pro.set("key", "nick");
					pro.set("seller", "");
					pro.set("foot_stout", Integer.parseInt(stout));
					pro.set("foot_normal", Integer.parseInt(normal));
					pro.set("foot_lean", Integer.parseInt(lean));
					boolean count = Db.save("u_product", pro);
					if (!count)
						suc = false;

					if (bsizes != null && !bsizes.equals("")) {
						String[] bsizeArray = bsizes.split(",");
						for (int i = 0; i < bsizeArray.length; i++) {
							final Record size = new Record();
							size.set("product_id", numid);
							size.set("sex", isman);
							size.set("french_size", sizearr[i]);
							size.set("size", bsizeArray[i]);
							size.set("style", styl);
							boolean count2 = Db.save("u_size", size);
							if (!count2)
								suc = false;
						}
					}
					if (gsizes != null && !gsizes.equals("")) {
						String[] gsizeArray = gsizes.split(",");
						for (int i = 0; i < gsizeArray.length; i++) {
							final Record size = new Record();
							size.set("product_id", numid);
							size.set("sex", isman);
							size.set("french_size", sizearr[i]);
							size.set("size", gsizeArray[i]);
							size.set("style", styl);
							boolean count2 = Db.save("u_size", size);
							if (!count2)
								suc = false;
						}
					}

					String[] comm1 = comment1.split(";");
					if (comm1.length > 0 && !comm1[0].equals("")) {
						for (int i = 0; i < comm1.length; i++) {
							final Record comment = new Record();
							comment.set("product_id", numid);
							comment.set("content", comm1[i]);
							comment.set("add_time", df.format(new Date()));
							comment.set("type", commentTag[0]);
							boolean count2 = Db.save("u_comment", comment);
							if (!count2)
								suc = false;
						}
					}
					String[] comm2 = comment2.split(";");
					if (comm2.length > 0 && !comm2[0].equals("")) {
						for (int i = 0; i < comm2.length; i++) {
							final Record comment = new Record();
							comment.set("product_id", numid);
							comment.set("content", comm2[i]);
							comment.set("add_time", df.format(new Date()));
							comment.set("type", commentTag[1]);
							boolean count2 = Db.save("u_comment", comment);
							if (!count2)
								suc = false;
						}
					}
					String[] comm3 = comment3.split(";");
					if (comm3.length > 0 && !comm3[0].equals("")) {
						for (int i = 0; i < comm3.length; i++) {
							final Record comment = new Record();
							comment.set("product_id", numid);
							comment.set("content", comm3[i]);
							comment.set("add_time", df.format(new Date()));
							comment.set("type", commentTag[2]);
							boolean count2 = Db.save("u_comment", comment);
							if (!count2)
								suc = false;
						}
					}
					String[] comm4 = comment4.split(";");
					if (comm4.length > 0 && !comm4[0].equals("")) {
						for (int i = 0; i < comm4.length; i++) {
							final Record comment = new Record();
							comment.set("product_id", numid);
							comment.set("content", comm4[i]);
							comment.set("add_time", df.format(new Date()));
							comment.set("type", commentTag[3]);
							boolean count2 = Db.save("u_comment", comment);
							if (!count2)
								suc = false;
						}
					}

					return suc;
				}
			});

			if (succeed) {
				renderText("添加成功！");
			} else {
				renderText("添加失败！");
			}
		} catch (Exception e) {
			renderText("添加失败！");
			e.printStackTrace();
		}
	}

	/**
	 * 截取返回的商品详情字符串，获取出鞋子尺码的list
	 * 
	 * @author 李彤彤
	 * @date 2015年10月19日 上午9:06:21
	 */
	private List<String> getSizes(String result) {

		List<String> list = new ArrayList<String>();
		int index = 0;
		while (true) {
			if (result.indexOf("运动鞋尺码:", index) != -1) {
				int a = result.indexOf("运动鞋尺码:", index);
				int b = result.indexOf(";", a);
				String size = result.substring(a + 6, b);
				list.add(size);
				index = b;
			} else {
				break;
			}
		}
		return list;
	}

	/**
	 * 获取评论详情进行解析
	 * 
	 * @author 李彤彤 2015年10月22日下午9:07:26
	 */
	public List<Comment> getEvaluateByNumId(String numId) {
		List<Comment> evaList = null;
		try {
			evaList = new ArrayList<Comment>();
			String result = API.getEvaluateByNumId(numId);
			JSONObject job = JSONObject.fromObject(result);
			JSONObject items = job.getJSONObject("traderates_get_response");
			JSONObject item = items.getJSONObject("trade_rates");
			JSONArray array = item.getJSONArray("trade_rate");
			Gson gson = new Gson();
			evaList = gson.fromJson(array.toString(), new TypeToken<List<Comment>>() {
			}.getType());
			// for (int i = 0; i < 10; i++) {
			// Comment eva = new Comment();
			// eva.setContent("鞋子质量非常好,穿起来很舒服.");
			// eva.setNick("卓梦");
			// eva.setCreated("2015-10-21 20:12:22");
			// eva.setItem_title("nick最新款运动鞋");
			// evaList.add(eva);
			// }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return evaList;
	}

	/**
	 * 获取到当前的用户，将用户信息放入session
	 */
	public void login() {
		User user = getSessionAttr("currentuser");
		if (null == user) {
			user = API.getCurrentUser();

		}
		renderJson("user", user.getNick());
	}

	public void setBanner() {
		String numId = getPara("numid");
		String desc = getPara("desc");
		API.updateProductDesc(numId, "哈哈 成功了");
	}

	/**
	 * 获得指定文件的byte数组
	 */
	public static byte[] getBytes(String filePath) {
		byte[] buffer = null;
		try {
			File file = new File(filePath);
			FileInputStream fis = new FileInputStream(file);
			ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
			byte[] b = new byte[1000];
			int n;
			while ((n = fis.read(b)) != -1) {
				bos.write(b, 0, n);
			}
			fis.close();
			bos.close();
			buffer = bos.toByteArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return buffer;
	}

	/**
	 * 上传图片到淘宝图片空间
	 * 
	 * @author 李彤彤
	 * @date 2015年10月28日 上午11:19:16
	 */
	public String uploadPicToTaobao(String bannertitle) {
		try {
			String pic = API.getPicFormTaobao(bannertitle);
			if (pic == null || "error".equals(pic)) {
				String url = ZmUtil.getFilePath("/image/" + bannertitle);
				byte[] aitem = getBytes(url);
				FileItem item = new FileItem(bannertitle, aitem);
				String result = API.uploadPicToTaobao(item, bannertitle);
				if (result != null && !result.equals("error")) {
					pic = API.getPicFormTaobao(bannertitle);
				} else {
					result = API.uploadPicToTaobao(item, bannertitle);
					if (result != null && !result.equals("error")) {
						pic = API.getPicFormTaobao(bannertitle);
					}
				}
			}
			return pic;
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

	}

	/**
	 * 跳转到模板页面
	 */
	public void templet() {
		Map<String, List<Templet>> kindsMap = new LinkedHashMap<String, List<Templet>>();
		List<String> titList = new ArrayList<String>();
		User user = getSessionAttr("currentuser");
		if (user != null) {
			List<Templet> list = Templet.dao.find("select title from u_templet where seller_id=" + user.getUser_id() + " group by title");
			for (int i = 0; i < list.size(); i++) {
				List<Templet> li = new ArrayList<Templet>();
				li = Templet.dao.find("select * from u_templet where seller_id=" + user.getUser_id() + " and title='" + list.get(i).getStr("title") + "'");
				kindsMap.put("tableList" + i, li);
				if (!titList.contains(li.get(0).getStr("title"))) {
					titList.add(li.get(0).getStr("title"));
				}
			}

		}
		if (kindsMap.size() == 0) {
			kindsMap = null;
		}
		setAttr("map", kindsMap);
		setAttr("titList", titList);
		setAttr("titSize", titList.size());
		render("seller/templet.html");
	}

	/**
	 * 插入模板
	 */
	public void insertTemplet() {
		try {
			String french = getPara("french");
			String size = getPara("size");
			String title = getPara("title");
			User user = getSessionAttr("currentuser");
			if (user == null) {
				renderText("添加失败，授权超时");
				return;
			}
			String sellerId = user.getUser_id();
			String[] frearr = french.split(";");
			String[] sizearr = size.split(";");
			String[] titlearr = title.split(";");
			if (titlearr.length == 0) {
				renderText("模板名字不能为空");
				return;
			}
			if (isrepeat(titlearr)) {
				renderText("模板名称不能相同！");
				return;
			}
			Db.update("delete from u_templet where seller_id='" + user.getUser_id() + "'");
			for (int i = 0; i < frearr.length; i++) {
				String[] freitem = frearr[i].split(",");
				String[] sizeitem = sizearr[i].split(",");
				for (int j = 0; j < freitem.length; j++) {
					if ((titlearr.length - 1) >= i) {
						Templet te = new Templet();
						te.set("title", titlearr[i]);
						te.set("seller_id", sellerId);
						te.set("french_size", freitem[j]);
						te.set("size", sizeitem[j]);
						te.save();
					}
				}

			}
			renderText("添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			renderText("添加失败");
		}
	}

	/**
	 * 判断数组中是否存在相同的数据
	 * 
	 * @param strs
	 * @return
	 */
	public boolean isrepeat(String[] strs) {
		boolean result = false;
		// 从第一个元素开始比较元素是不是有相同的出现
		for (int i = 0; i < strs.length; i++) {
			for (int j = i + 1; j < strs.length; j++) {
				// 如果元素相同，保存到set中
				if (strs[i].equals(strs[j])) {
					result = true;
				}
			}
		}
		return result;
	}

	/**
	 * 通过用户id和title获取模板的尺码列表
	 */
	public void getSizeBytitle() {
		String title = getPara("title");
		User user = getSessionAttr("currentuser");
		List<Templet> li = null;
		if (user != null) {
			li = Templet.dao.find("select * from u_templet where seller_id=" + user.getUser_id() + " and title='" + title + "'");
		}
		renderJson(li);
	}

	/**
	 * 跳转到设置banner的页面
	 */
	public void toSetBanner() {
		String numids = getPara("numids");
		setAttr("numids", numids);
		render("seller/chosebanner.html");
	}

	/**
	 * 设置banner
	 */
	public void publish() {
		try {
			User user = getSessionAttr("currentuser");
			String numids = getPara("numids");
			String banner = getPara("banner");
			String[] numarr = numids.split(",");
			String pic = uploadPicToTaobao(banner);
			if (pic.equals("error")) {
				pic = uploadPicToTaobao(banner);
				if (pic.equals("error")) {
					pic = uploadPicToTaobao(banner);
				}
				if (pic.equals("error")) {
					renderText("网络异常，请稍后再试");
					return;
				}
			}
			boolean is = true;
			for (int i = 0; i < numarr.length; i++) {
				Product pro = Product.dao.findFirst("select * from u_product where product_id=" + numarr[i]);
				if (pro != null) {
					pro.set("banner_name", banner);
					pro.set("publish", "1");
					pro.set("banner_url", pic);
					pro.update();
				}
				String desc = API.getProductDetail(numarr[i]);
				String desc1 = "";
				if (!desc.equals("error")) {
					String aa = "<a target='_blank'  href='http://shoesize.play.m.jaeapp.com/front/toFoot?id=" + numarr[i] + "&id2=" + user.getUser_id()
							+ "' name='zhuomeng'><img src='" + pic + "'/ width=100%></img></a><br>";
					desc1 = delImg(desc);
					aa += desc1;
					String result = API.updateProductDesc(numarr[i], aa);
					LogFactory.getLog(SellerAdminController.class).error("上传结果：" + result);
					if (result.equals("error")) {
						API.updateProductDesc(numarr[i], aa);
					}
				} else {
					desc = API.getProductDetail(numarr[i]);
					if (!desc.equals("error")) {
						String aa = "<a target='_blank' href='http://shoesize.play.m.jaeapp.com/front/toFoot?id=" + numarr[i] + "&id2=" + user.getUser_id()
								+ "' name='zhuomeng'><img src='" + pic + "'/ width=100%></img></a><br>";
						desc1 = delImg(desc);
						aa += desc1;
						String result = API.updateProductDesc(numarr[i], aa);
						LogFactory.getLog(SellerAdminController.class).error("上传结果：" + result);
						if (result.equals("error")) {
							API.updateProductDesc(numarr[i], aa);
						}
					} else {
						is = false;
					}
				}
			}
			if (is) {
				renderText("操作成功！");
			} else {
				renderText("更新宝贝失败,请重试！");
			}
		} catch (Exception e) {
			Log.errorLogger.error(e.getMessage());
			renderText("操作失败！");
			e.printStackTrace();
		}

	}

	public void useTutorial() {
		setAttr("state", "1");
		render("seller/use_tutorial.html");
	}

	public void video() {
		setAttr("state", "1");
		render("seller/video.html");
	}

	public void noLineUseTutorial() {
		setAttr("state", "1");
		render("seller/noline_use_tutorial.html");
	}

	public void beCareful() {
		setAttr("state", "1");
		render("seller/becareful.html");
	}

	/**
	 * 获取出商品详情后，判断是不是已经上传过ｂａｎｎｅｒ，上传过就先删除。
	 * 
	 * @param desc
	 * @return
	 */
	public String delImg(String desc) {
		String result = desc;
		while (true) {
			int a = result.indexOf("name=\"zhuomeng\"");
			if (a != -1) {
				int b = result.indexOf("<br>", a);
				if (b != -1) {
					String now = result.substring(a, b + 4);
					String[] aa = result.split(now);
					result = aa[0] + aa[1];
				} else {
					break;
				}
			} else {
				break;
			}
		}
		LogFactory.getLog(SellerAdminController.class).error("删过之后:" + result);
		return result;
	}

	public static void main(String[] args) {
		SellerAdminController sell = new SellerAdminController();
		sell.delImg("aa");
	}
}